﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp.Study.Test
{
    /// <summary>
    /// with表达式复制一个对象，更改部分属性
    /// </summary>
    public class with表达式
    {
        public record NamedPoint(string Name, int X, int Y);
        public static void Go()
        {
            Test();
        }

        private static void Test()
        {
            int i = 3;

            var p1 = new NamedPoint("孔明", 66, 6666);
            Console.WriteLine($"{nameof(p1)}:{p1}");

            var p1new = p1 with { };
            Console.WriteLine($"{nameof(p1new)}:{p1new}");

            var p2 = p1 with { Name = "孔明2", X = 99 };
            Console.WriteLine($"{nameof(p2)}:{p2}");

            var p3 = p1 with { Name = "孔明3", Y = 9999 };
            Console.WriteLine($"{nameof(p3)}:{p3}");

            var apple = new { Item = "apple", Price = 1.90 };
            Console.WriteLine($"{nameof(apple)}:{apple}");

            var apple2 = apple with { Item = "apple2", Price = 2.10 };
            Console.WriteLine($"{nameof(apple2)}:{apple2}");
        }
    }
}
